From fc2da1a137d256f167a10a9b2a4775b93f1f6cd4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 1 Oct 2010 14:54:11 -0400 Subject: [PATCH] Migration guide: Add an example for creating custom cursors --- docs/reference/gtk/migrating-2to3.xml | 52 +++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/docs/reference/gtk/migrating-2to3.xml b/docs/reference/gtk/migrating-2to3.xml index ab883c730c..447dc17c1d 100644 --- a/docs/reference/gtk/migrating-2to3.xml +++ b/docs/reference/gtk/migrating-2to3.xml @@ -393,9 +393,57 @@ cairo_destroy (cr); Replace GdkPixmap by cairo surfaces The #GdkPixmap object and related functions have been removed. - In the cairo-centric world of GTK+ 3, cairo surfaces - take over the role of pixmaps. + In the cairo-centric world of GTK+ 3, cairo surfaces take over + the role of pixmaps. + + Creating custom cursors + + One place where pixmaps were commonly used is to create custom + cursors: + +GdkCursor *cursor; +GdkPixmap *pixmap; +cairo_t *cr; +GdkColor fg = { 0, 0, 0, 0 }; + +pixmap = gdk_pixmap_new (NULL, 1, 1, 1); + +cr = gdk_cairo_create (pixmap); +cairo_rectangle (cr, 0, 0, 1, 1); +cairo_fill (cr); +cairo_destroy (cr); + +cursor = gdk_cursor_new_from_pixmap (pixmap, pixmap, &fg, &fg, 0, 0); + +g_object_unref (pixmap); + + The same can be achieved without pixmaps, by drawing onto + an image surface: + +GdkCursor *cursor; +cairo_surface_t *s; +cairo_t *cr; +GdkPixbuf *pixbuf; + +s = cairo_image_surface_create (CAIRO_FORMAT_A1, 3, 3); +cr = cairo_create (s); +cairo_arc (cr, 1.5, 1.5, 1.5, 0, 2 * M_PI); +cairo_fill (cr); +cairo_destroy (cr); + +pixbuf = gdk_pixbuf_get_from_surface (NULL, s, + 0, 0, 0, 0, + 3, 3); + +cairo_surface_destroy (s); + +cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, 0, 0); + +g_object_unref (pixbuf); + + +
-- 2.30.2